package leetcode;

/**
 * Created by 林剑 on 2016/10/15.
 */
public class leetcode419 {
    public int countBattleships(char[][] board) {
        int m = board.length;
        if (m==0) return 0;
        int n = board[0].length;

        int count=0;

        for (int i=0; i<m; i++) {
            for (int j=0; j<n; j++) {
                if (board[i][j] == '.') continue;
                if (i > 0 && board[i-1][j] == 'X') continue;
                if (j > 0 && board[i][j-1] == 'X') continue;
                count++;
            }
        }

        return count;
    }

    public static void main(String[] args) {
        leetcode419 leetcode419 = new leetcode419();
        char[][] a= {{'X','.','.','X'},{'.','.','.','X'},{'.','.','.','X'}};
        char[][] b ={{'X','.','X','X'}};
        System.out.println(leetcode419.countBattleships(b));
    }
}
